﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Moq;

namespace MoqContrib.AutoMock.Tests.TheMockHeap
{
    [TestFixture]
    class WhenTryingToRememberMocks
    {
        #region Types used for testing
        public interface IService { }
        public class Service : IService { }
        #endregion

        [Test]
        public void I_can_get_mocks_that_were_previously_set()
        {
            var heap = new MockHeap();
            var mock = new Mock<IService>();
            heap[typeof(IService)] = mock;

            var result = heap[typeof(IService)];
            Assert.That(result, Is.SameAs(mock));
        }

        [Test]
        public void A_mock_of_a_class_is_different_from_a_mock_of_an_interface()
        {
            var heap = new MockHeap();
            var mock = new Mock<Service>();
            heap[typeof(Service)] = mock;

            Mock m = null;
            Assert.Throws<IndexOutOfRangeException>(() => m = heap[typeof(IService)]);
        }


        [Test]
        public void If_I_have_a_mock_then_I_ContainsType()
        {
            var heap = new MockHeap();
            var mock = new Mock<IService>();
            heap[typeof(IService)] = mock;

            var result = heap.ContainsType(typeof(IService));
            Assert.That(result, Is.True);
        }
        [Test]
        public void If_I_dont_have_a_mock_then_I_dont_ContainsType()
        {
            var heap = new MockHeap();
            var mock = new Mock<IService>();
            heap[typeof(IService)] = mock;

            var result = heap.ContainsType(typeof(Service));
            Assert.That(result, Is.False);
        }
    }
}
